<?php

namespace App;

use Carbon\Carbon;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;

class GroupMaster extends Model
{
    protected $guarded=[];
    protected $appends=[
        'end_time_timestamp'
    ];
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }
    public function user()
    {
        return $this->belongsTo(User::class,'uid','id');
    }
    public function group_buy()
    {
        return $this->belongsTo(GroupBuy::class,'group_buy_id','id');
    }
    public function goods()
    {
        return $this->hasOne(Goods::class,'id','goods_id');
    }
    public function group_items()
    {
        return $this->hasMany(GroupBuyItem::class);
    }
    public function getEndTimeTimestampAttribute()
    {
        return Carbon::createFromTimeString($this->end_time)->timestamp;
    }
}
